package red.mlz.module.module.smslog.service;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import red.mlz.module.module.smslog.entity.SmsLog;
import red.mlz.module.module.smslog.mapper.SmsLogMapper;

@Service
public class SmsLogService {

    @Autowired
    private SmsLogMapper smsLogMapper;

    public SmsLog getById(Long sms_logId) {

        return smsLogMapper.getById(sms_logId);
    }

    public SmsLog extractById(Long sms_logId) {

        return smsLogMapper.extractById(sms_logId);
    }

    public Integer insert(SmsLog entity) {

        return smsLogMapper.insert(entity);
    }

    public Integer update(SmsLog entity) {

        return smsLogMapper.update(entity);
    }

    public Integer delete(Long id, Integer updateTime) {

        return smsLogMapper.delete(updateTime, id);
    }

    public SendSmsResponse sendSync(String phone, String signName, String templateCode, String params) throws ClientException, ClientException {
        IClientProfile profile = DefaultProfile.getProfile(
                "cn-hangzhou",
                "LTAI5tHDMd8TjPzwaQYYfcLH",    // AccessKey ID
                "Fe3buPjw6wU78Mje0nrHD9GgsTwYzr" //  AccessKey Secret
        );
        IAcsClient client = new DefaultAcsClient(profile);

        SendSmsRequest request = new SendSmsRequest();
        request.setPhoneNumbers(phone);
        request.setSignName(signName);
        request.setTemplateCode(templateCode);
        request.setTemplateParam(params);
        return client.getAcsResponse(request);
    }
}
